const Controller = require('egg').Controller

class IndexController extends Controller {
  async login () {
    const {ctx, app} = this
    const {username: u1, password: p1} = ctx.request.body
    const results = await app.mysql.select('user', {
      where: {
        username: u1,
        password: p1
      }
    })
    if (results.length) {
      ctx.body = {
        code: '0',
        msg: '登录成功',
        data: {
          name: results[0].name,
          mobile: results[0].mobile
        }
      }
    } else {
      ctx.body = {
        code: '-1',
        msg: '用户名或密码错误',
        data: ''
      }
    }
  }
}

module.exports = IndexController
